var table,$;
layui.use(['table'],function () {
    table = layui.table;
    $ = layui.$;
    initZpxxData();
    $("#search").click(function () {
        initZpxxData();
    })
    $("#code-1").click(function () {
        reload(-1)
    })
    $("#code1").click(function () {
        reload(1)
    })
    $("#code2").click(function () {
        reload(2)
    })
    table.on('toolbar(zpxxList)', function(obj){
        // var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
            case 'add':
                layer.msg('添加');
                break;
            case 'delete':
                layer.msg('删除');
                break;
            case 'update':
                layer.msg('编辑');
                break;
        };
    });
    table.on('tool(zpxxList)', function(obj){
        var data = obj.data;
        if(obj.event === 'del'){
            delZpxx(data,data.id);
        }
    });

})

function initZpxxData() {
    var id = $('#id').val();
    var schoolName = $('#schoolName').val();
    var collegeName = $('#collegeName').val();
    var assoName = $('#assoName').val();

    if(id == ""){
        id = 0;
    }
    table.render({
        elem: '#zpxxList'
        , url: '/zpxx/getZpxx'
        , method: 'get'
        , where: {
            id:id,
            schoolName:schoolName,
            collegeName:collegeName,
            assoName:assoName
        }
        , limit: 10
        , page: true
        ,toolbar: 'default'
        , cols: [[
            {type: 'numbers'}
            , {field: 'id', title: 'ID', width: 80, unresize: true, sort: true}
            , {field: 'assoId', title: '社团ID',width: 80}
            , {field: 'schoolName', title: '学校名称', width: 110}
            , {field: 'collegeName', title: '所属学院', width: 110}
            , {field: 'assoName', title: '社团名称', width: 110}
            , {field: 'assoType', title: '社团种类', width: 110}
            , {field: 'assoType', title: '社团种类', width: 110}
            , {field: 'avatarUrl', title: '招聘头像', width: 110}
            , {field: 'studentName', title: '负责人姓名', width: 110}
            , {field: 'stjj', title: '社团简介', width: 110,templet:function (d) {
                     return '<span><a onclick=\"showStjj('+'\''+d.stjj+'\''+')\">'+d.stjj+'</a></span>'
    }}
            , {field: 'stxq', title: '社团详情', width: 110,templet:function (d) {
                    return '<span><a onclick=\"showStxq('+'\''+d.stxq+'\''+')\">'+d.stxq+'</a></span>'
                }}
            , {field: 'startTime', title: '招聘开始时间', width: 110}
            , {field: 'createTime', title: '简介', width: 80}
            // ,{field:'code',title:'状态',fixed:'right',templet:function (d) {
            //         if(d.code ==0 ){return '<span><a onclick=\"changeCode('+'\''+d+'\'\,1'+')\">未通过</a></span>'}
            //         if(d.code ==1){return '<span><a onclick=\"changeCode('+'\''+d+'\'\,0'+')\">已通过</a></span>'}
            //     }}
            ,{field:'code',title:'状态',fixed:'right',templet:'#codeTpl'}
            ,{fixed:'right', title:'操作',width:140,align:'center', toolbar:'#optBar'}
        ]]
    })
}
function reload(e) {
    table.reload('zpxxList',{
        url:"/zpxx/getZpxx",
        where:{code:e}
    })
}
var changeCode = function (d,e) {
    var changeCodeVO = {"id":d, "code": e}
    console.log(d)
    console.log(e)
    $.ajax({
        type: "POST",
        data:JSON.stringify(changeCodeVO),
        url: "/zpxx/changeCode",
        headers	:{'Content-Type': 'application/json'},

        success: function (data) {
            if(data.code==1){
                layer.alert("修改成功",function(){
                    layer.closeAll();
                    initZpxxData()
                });
            }else{
                layer.alert(data.msg,function () {
                    layer.closeAll();
                    initZpxxData()
                });

            }
        },
        error: function () {
            layer.alert("操作请求错误，=-=",function(){
                layer.closeAll();
                //加载load方法
                initZpxxData()
            });
        }
    });
}
var showStjj = function (e) {

    layer.alert(e)
}
var showStxq = function(e) {
    layer.alert(e)
}
function delZpxx(obj,id) {
    if(null!=id){
        layer.confirm('您确定要删除'+id+'招聘信息吗？', {
            btn: ['确认','返回'] //按钮
        }, function(){
            $.post("/zpxx/delZpxx",{"id":id},function(data){
                if(data.code==1){
                    //回调弹框
                    layer.alert("删除成功！",function(){
                        layer.closeAll();
                        initZpxxData();
                    });
                }else{
                    layer.alert(data.msg,function(){
                        layer.closeAll();
                        initZpxxData();

                    });
                }
            });}, function(){
            layer.closeAll();
        });
    }
}
